﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Resources;
using System.IO;
using Microsoft.Xna.Framework.Media;
using System.Windows.Navigation;
using System.Windows.Threading;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using ActivityTracker;
using System.Diagnostics;
using System.Collections;
using System.Device.Location;
using Expression.Blend.SampleData.MenuDataSource;
using Microsoft.Phone.Tasks;

using ActivityTracker.Library;
using Microsoft.Phone.Shell;
using Common.Library;
using CommonControls;


namespace ActivityTracker
{
    public partial class StartActivity : PhoneApplicationPage
    {
        #region Global Varaibles

        int LastHistoryid = 1;
        int FirstHistoryid = 1;
        int count = 0;
        bool NewPageInstance = false;
        private DispatcherTimer timer;
        private DispatcherTimer tipsTimer;
        GeoCoordinateWatcher watcher = null;
       // AboutUs objAboutUs = new AboutUs();
        List<LapProp> objLapProp;
        int tipsStartIndex = 1;
        int tipsLastIndex = 10;
        bool IsTipsAndTricksEnable;
        //tips and tricks links
        string link = "";
        string linkContent = "";

        #endregion

        #region Global Objects

        Actvity objActivity = new Actvity();
        RunningActivity objRunningActivity = new RunningActivity();
        ActivityData objActivityData = new ActivityData();
        History objHistory = new History();
        Maps objMaps = new Maps();
        Background objBackground = new Background();
        TipsAndTricks objTipsAndTricks = new TipsAndTricks();
       
        #endregion

        #region Constructor

        public StartActivity()
        {
            InitializeComponent();
            objLapProp = new List<LapProp>();
            panoramaPage.Background = objBackground.LoadBackground();
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
            tipsTimer = new DispatcherTimer();
            tipsTimer.Interval = TimeSpan.FromSeconds(8);
            tipsTimer.Tick += new EventHandler(tipsTimer_Tick);
            NewPageInstance = true;
            
        }

        #endregion

        #region PageLoad

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (tblkActName.Text == "")
                {
                    LoadRunningActiviy();
                    //AboutUs about = new AboutUs();
                    //AboutGrid.Children.Add(about);
                    if (panoramaPage.SelectedIndex == 0)
                    {
                        IsTipsAndTricksEnable = SettingsHelper.getBoolValue("TipsAndTricks");
                        if(IsTipsAndTricksEnable)
                            TipsAndTricks();
                    }
                }
             
                LoadHistory();
                //lbxAboutUs.ItemsSource = objAboutUs.LoadAboutUsItems();
                if (NewPageInstance)
                {
                    string actId = "";
                    if (NavigationContext.QueryString.TryGetValue("actId", out actId))
                    {
                        tblkActName.Text = objActivity.GetActivityName(actId);
                        App.actId = actId;
                    }
                }
                NewPageInstance = false;
            }
            catch (Exception ex)
            {
                string mess = "Exception in PhoneApplicationPage_Loaded Method In StartActivity file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void clearTextValues()
        {
            tblkActName.Text = "";
            btnFinish.Visibility = Visibility.Collapsed;
            btnLap.Visibility = Visibility.Collapsed;
            tblkStatus.Visibility = Visibility.Collapsed;
            tblktimer.Text = "00:00:00";
            tblkStartTime.Text = "";
            tblkEndTime.Text = "";
            objLapProp.Clear();
            lbxLaps.ItemsSource = objLapProp;
        }

        #endregion

        #region Tips And Tricks

        private void TipsAndTricks()
        {
            tipsTimer.Start();
        }

        void tipsTimer_Tick(object sender, EventArgs e)
        {
            if (App.runningActId == null)
            {
                if (tipsStartIndex <= tipsLastIndex)
                {
                    objTipsAndTricks.GetTipsText(tipsStartIndex, out link, out linkContent);
                    if (link != "")
                    {
                        hlink.Text = linkContent;
                        hlink.Visibility = Visibility.Visible;
                    }
                    else
                        hlink.Visibility = Visibility.Collapsed;

                    FadingMessage msg = new FadingMessage()
                    {
                        MessageToShow = theMessage,
                        VerticalAlignment = System.Windows.VerticalAlignment.Bottom,
                        HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                       
                    };
                    msg.Show(8000);
                    tipsStartIndex += 1;
                    if (tipsStartIndex > tipsLastIndex)
                        tipsStartIndex = 1;
                }
            }
            else
            {
                tipsTimer.Stop();
            }
        }

        private void hlink_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri(link, UriKind.Relative));
        }

        #endregion

        #region Start Activity

        private void tblkActName_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            tipsTimer.Stop();
            NavigationService.Navigate(new Uri("/Views/Activities/ActivityAndScheduleSelection.xaml", UriKind.Relative));
        }

        private void imgStart_Click(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (tblkActName.Text != "")
                    tblkActName.IsHitTestVisible = false;
                if (tblkActName.Text != "")
                {
                    DateTime tempDate = DateTime.Now;
                    timer.Start();
                    App.runningActId = App.actId;
                    App.actStartDate = tempDate;
                    App.lapStartTime = tempDate;

                    if (App.runningActId != null && App.actId != null)
                        tblkStartTime.Text = tempDate.ToShortTimeString();
                    objHistory.SaveActivity(App.actId, tblkActName.Text, App.actStartDate.ToShortDateString(), tblkStartTime.Text);

                    //Saving Running Activity Data
                    objRunningActivity.SaveRunningActivity(App.actId, tblkActName.Text, App.actStartDate.ToString(), App.actStartDate.ToShortTimeString(), App.lapStartTime.ToString(), objLapProp);
                    //LocationTracking
                    TrackLocation();
                    //code to run under lock
                    bool rununderlock = false;
                    rununderlock = SettingsHelper.getBoolValue("runUnderLock");
                    ApplicationIdleModeHelper.Current.RunsUnderLock = rununderlock;

                    btnFinish.Visibility = Visibility.Visible;
                    btnLap.Visibility = Visibility.Visible;
                    tblkEndTime.Text = "";
                }
            }
            catch (Exception ex)
            {
                string mess = "Exception in imgStart_Click Method In StartActivity file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void imgFinish_Click(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (tblkActName.Text != "")
                {
                    timer.Stop();
                    tblkEndTime.Text = DateTime.Now.ToShortTimeString();
                    tblkActName.IsHitTestVisible = true;

                    //location tracking
                    if (objMaps.IsMapVisible(App.actId) && SettingsHelper.getBoolValue("GeoLocationStatus"))
                        StopLocationTracking();

                    //saving history
                    int totDur = objHistory.CalDurInMins(objLapProp, tblktimer.Text);
                    if (totDur > 0)
                    {
                        //Remove if already saved
                        objRunningActivity.RemoveSavedRunningActivity(App.actId, tblkActName.Text, App.actStartDate.ToString(), App.actStartDate.ToShortTimeString());
                        objHistory.SaveActivityHistory(SettingsHelper.getStringValue("hisId"), tblkEndTime.Text, totDur);
                        objHistory.SaveTotalduration(App.actId, tblkActName.Text, totDur, App.actStartDate.ToShortDateString());
                       
                        LoadHistory();
                    }

                    //code to run under lock
                    SettingsHelper.Save("runUnderLock", "false");
                    ApplicationIdleModeHelper.Current.RunsUnderLock = false;

                    App.lapCount = 0;
                    App.actId = null;
                    App.runningActId = null;
                    tblktimer.Text = "00:00:00";
                    btnStart.Visibility = Visibility.Visible;
                    HideAllControls();
                    panoramaPage.DefaultItem = history;
                }
            }
            catch (Exception ex)
            {
                string mess = "Exception in imgFinish_Click Method In StartActivity file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                ex.Data.Add("actStartTime_imgFinish_Click", tblkStartTime.Text);
                ex.Data.Add("actEndTime_imgFinish_Click", tblkEndTime.Text);
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void imgLap_Click(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (tblkActName.Text != "")
                    tblkActName.IsHitTestVisible = false;
                if (tblkActName.Text != "" && App.runningActId != null)
                {
                    SaveLap();
                    //Saving Running Activity Data
                    objRunningActivity.SaveRunningActivity(App.actId, tblkActName.Text, App.actStartDate.ToString(), App.actStartDate.ToShortTimeString(), App.lapStartTime.ToString(), objLapProp);
                }
            }
            catch (Exception ex)
            {
                string mess = "Exception in imgLap_Click Method In StartActivity file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void panoramaPage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (panoramaPage.SelectedIndex == 0)
            {
                IsTipsAndTricksEnable = SettingsHelper.getBoolValue("TipsAndTricks");
                if (IsTipsAndTricksEnable)
                    TipsAndTricks();
            }
            else
            {

                    tipsTimer.Stop();
            }
        }

        //Custom Methods
        void timer_Tick(object sender, EventArgs e)
        {
            try
            {
                ShowTime();
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in timer_Tick Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exnew;
            }
        }

        private void ShowTime()
        {
            DateTime LocalCurrentTime = System.DateTime.Now;
            DateTime LocalStartTime = System.DateTime.Now;
            try
            {
                DateTime dateNow = DateTime.Now;
                DateTime UniveralCurrentTime = TimeZoneInfo.ConvertTime(dateNow, TimeZoneInfo.Utc);
                LocalCurrentTime = TimeZoneInfo.ConvertTime(UniveralCurrentTime, TimeZoneInfo.Local);

                DateTime UniveralStartTime = TimeZoneInfo.ConvertTime(App.lapStartTime, TimeZoneInfo.Utc);
                LocalStartTime = TimeZoneInfo.ConvertTime(UniveralStartTime, TimeZoneInfo.Local);

                if ((Convert.ToDateTime(LocalCurrentTime) >= Convert.ToDateTime(LocalStartTime)))
                {
                    TimeSpan elapsedTime = Convert.ToDateTime(LocalCurrentTime).Subtract(Convert.ToDateTime(LocalStartTime));
                    tblktimer.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", elapsedTime.Hours, elapsedTime.Minutes, elapsedTime.Seconds);
                    if (elapsedTime.Hours == 23 && elapsedTime.Minutes == 59 && elapsedTime.Seconds == 59)
                    {
                        SaveLap();
                        objRunningActivity.SaveRunningActivity(App.actId, tblkActName.Text, App.actStartDate.ToString(), App.actStartDate.ToShortTimeString(), App.lapStartTime.ToString(), objLapProp);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in ShowTime Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace + "\n TimeZoneInfo:" + TimeZoneInfo.Local + "\n\n StartTime:" + LocalStartTime.ToString() + "\n\n CurrentTime:" + LocalCurrentTime.ToString() + "\n\n");
                throw exnew;
            }
        }

        private void SaveLap()
        {
            App.lapStartTime = DateTime.Now;
            List<LapProp> objlist = new List<LapProp>();
            objLapProp = objlist = objActivityData.GenerateLaps(tblkActName.Text, App.actStartDate, App.lapStartTime, tblktimer.Text, App.lapCount += 1, objLapProp);
            LoadLap(objlist);
            tblktimer.Text = "00:00:00";
        }

        private void LoadLap(List<LapProp> objlist)
        {
            objlist = objlist.OrderByDescending(x => x.LapId).ToList();
            lbxLaps.ItemsSource = objlist;
        }

        private void LoadRunningActiviy()
        {
            try
            {
                int lapCount = 0;
                List<LapProp> laplist = new List<LapProp>();
                ActivityProp runnginActivity = objRunningActivity.LoadRunningActivity(out lapCount, out laplist);
                if (runnginActivity.ActId != null)
                {
                    App.lapCount = lapCount;
                    App.actId = runnginActivity.ActId;
                    App.runningActId = App.actId;
                    tblkActName.Text = runnginActivity.ActName;
                    App.actStartDate = Convert.ToDateTime(runnginActivity.ActStartDate);
                    tblkStartTime.Text = App.actStartDate.ToShortTimeString();
                    App.lapStartTime = Convert.ToDateTime(runnginActivity.ActLapStartTime);
                    LoadLap(laplist);
                    objLapProp = laplist;
                    ShowTime();
                    timer.Start();
                    //LocationTracking
                    TrackLocation();
                    btnStart.Visibility = Visibility.Collapsed;
                    btnFinish.Visibility = Visibility.Visible;
                    btnLap.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in LoadRunningActivity Method In ActivityTracker.Library.Activity.RunningActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exNew;
            }
        }

        private void HideAllControls()
        {
            btnFinish.Visibility = Visibility.Collapsed;
            btnLap.Visibility = Visibility.Collapsed;
            tblkStartTime.Visibility = Visibility.Collapsed;
            tblkEndTime.Visibility = Visibility.Collapsed;
            tblkStatus.Visibility = Visibility.Collapsed;
            objLapProp = new List<LapProp>();
            lbxLaps.ItemsSource = objLapProp;
            tblkActName.Text = "";
        }

        #endregion

        #region Menu Section

        //Events
        private void lbxMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lbxMenu.SelectedIndex == -1)
                return;
            lbxMenu.SelectedIndex = -1;
            switch (((e.AddedItems[0] as Item).MenuId).ToString())
            {
                case "1":
                    NavigationService.Navigate(new Uri("/Views/Activities/MyActivities.xaml", UriKind.Relative));
                    break;
                case "2":
                    NavigationService.Navigate(new Uri("/Views/Charts/TimeSpentMenu.xaml", UriKind.Relative));
                    break;
                case "3":
                    NavigationService.Navigate(new Uri("/Views/Help/HelpMenu.xaml", UriKind.Relative));
                    break;
                case "4":
                    NavigationService.Navigate(new Uri("/Views/Themes/BackgroundSelection.xaml", UriKind.Relative));
                    break;
                case "5":
                    NavigationService.Navigate(new Uri("/Views/Settings/Settings.xaml", UriKind.Relative));
                    break;
            }
        }

        #endregion

        #region History Section

        //Events
        private void contextMenu_Delete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ListBoxItem selectedListBoxItem = this.lbxHistory.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;
                if (selectedListBoxItem == null)
                    return;
                string hisId = (selectedListBoxItem.Content as ActivityProp).HisId.ToString();
                objHistory.DeleteHistory(hisId);
                LoadHistory();
            }
            catch (Exception ex)
            {
                string mess = "Exception in contextMenu_Delete_Click Method In StartActivity file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void lbxHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (lbxHistory.SelectedIndex == -1)
                    return;
                string actId = (lbxHistory.SelectedItem as ActivityProp).ActId.ToString();
                string actName = (lbxHistory.SelectedItem as ActivityProp).ActName;
                string actStartDate = (lbxHistory.SelectedItem as ActivityProp).ActStartDate;
                string hisId = ((lbxHistory.SelectedItem as ActivityProp).HisId).ToString();
                if (actName != "get more")
                    NavigationService.Navigate(new Uri("/Views/Charts/ProgressMenu.xaml?hisId=" + hisId + "&actId=" + actId + "&actStartDate=" + actStartDate, UriKind.Relative));
                else
                {
                    FirstHistoryid = FirstHistoryid - 10;
                    count = count + 10;
                    if (FirstHistoryid < 0)
                        FirstHistoryid = 1;
                    lbxHistory.ItemsSource = objHistory.LoadHistory(FirstHistoryid, LastHistoryid, count);
                    lbxHistory.ScrollIntoView(lbxHistory.Items[count - 10]);
                }
            }
            catch (Exception ex)
            {
                string mess = "Exception in lbxHistory_SelectionChanged Method In StartActivity file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void imgAddHistory_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Activities/AddPastHistoryFromPanorama.xaml", UriKind.Relative));
        }

        // Custum Methods
        private void LoadHistory()
        {
            try
            {
                LastHistoryid = objHistory.GetLastHistoryId();
                FirstHistoryid = LastHistoryid - 9;
                count = 10;
                if (FirstHistoryid < 0)
                    FirstHistoryid = 1;
                lbxHistory.ItemsSource = objHistory.LoadHistory(FirstHistoryid, LastHistoryid, count);
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in LoadHistory Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                foreach (DictionaryEntry d in ex.Data)
                    exnew.Data.Add(d.Key, d.Value);
                throw exnew;
            }
        }

        #endregion

        #region Location Tracking

        private void TrackLocation()
        {
            try
            {
                bool locationtracking = objMaps.IsMapVisible(App.actId);
                bool GeoLocationStatus = SettingsHelper.getBoolValue("GeoLocationStatus");

                if (locationtracking && GeoLocationStatus)
                {
                    tblkStatus.Visibility = Visibility.Visible;
                    StartLocationTracking();
                }
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in TrackLocation Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exnew;
            }
        }

        private void StartLocationTracking()
        {
            try
            {
                SettingsHelper.Save("IsWatcherCreated", "false");
                if (watcher == null)
                {
                    string locAccuracy = SettingsHelper.getStringValue("LocAccuracy");
                    if (locAccuracy == "" || locAccuracy == "Default")
                        watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
                    else
                        watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
                    SettingsHelper.Save("IsWatcherCreated", "true");
                    watcher.MovementThreshold = 30; // 30 meters.
                    watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
                    watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
                }
                else
                {
                    SettingsHelper.Save("IsWatcherCreated", "false");
                }
                watcher.Start();
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in StartLocationTracking Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exNew;
            }
        }

        void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
        {
            try
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => MyStatusChanged(e));
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in watcher_StatusChanged Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exNew;
            }
        }

        void MyStatusChanged(GeoPositionStatusChangedEventArgs e)
        {
            try
            {
                switch (e.Status)
                {
                    case GeoPositionStatus.Disabled:
                        if (watcher.Permission == GeoPositionPermission.Denied)
                            tblkStatus.Text = "You have disabled the location Service on your device";
                        else
                            tblkStatus.Text = "Location service is not functioning on this device";
                        break;
                    case GeoPositionStatus.Initializing:
                        tblkStatus.Text = "Location service is initializing...";
                        break;
                    case GeoPositionStatus.NoData:
                        tblkStatus.Text = "Location data is not available";
                        break;
                    case GeoPositionStatus.Ready:
                        tblkStatus.Text = "Location data is available";
                        break;
                }
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in MyStatusChanged Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exNew;
            }
        }

        void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            try
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => MyPositionChanged(e));
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in watcher_PositionChanged Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exNew;
            }
        }

        void MyPositionChanged(GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            try
            {
                int locCount = 1;
                string latitude = e.Position.Location.Latitude.ToString("0.0000");
                string longitude = e.Position.Location.Longitude.ToString("0.0000");
                //altitude = e.Position.Location.Altitude.ToString("0.0000");
                if (latitude != null && longitude != null)
                {   //incrementing and saving LocationCount
                    if (SettingsHelper.getStringValue("locCount") != "")
                        locCount = Convert.ToInt32(SettingsHelper.getStringValue("locCount"));
                    tblkStatus.Text = "Location data is available at point " + locCount.ToString();

                    //saving location points
                    string historyId = "";
                    bool isWatcherStarted = false;
                    historyId = SettingsHelper.getStringValue("hisId");
                    isWatcherStarted = SettingsHelper.getBoolValue("IsWatcherCreated");
                    if (isWatcherStarted)
                        objMaps.SaveLocations(latitude, longitude, historyId, DateTime.Now.ToString(), locCount.ToString());
                    locCount++;
                    SettingsHelper.Save("locCount", locCount.ToString());
                }
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in MyPositionChanged Method In StartActivity file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exNew;
            }
        }

        private void StopLocationTracking()
        {
            try
            {
                watcher.Stop();
                watcher.Dispose();
                watcher = null;
            }
            catch (Exception ex)
            {
                string mess = "Exception in StopLocationTracking Method In StartActivity file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        #endregion

        
    }
}








